package cn.fastoo.web.backstage.utils;

import cn.fastoo.web.backstage.service.system.ShiroDbRealm;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

public class ShiroUtils {
	/**
	 * 获取当前用户
	 * 
	 * @return
	 */
	public static Subject getLoginUser() {
		return SecurityUtils.getSubject();
	}

 

	/**
	 * 取出Shiro中的当前用户LoginName.
	 * 
	 * @return
	 */
	public static String getLoginName() {
		ShiroDbRealm.ShiroUser user = (ShiroDbRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal();
		return user.loginName;
	}

	/**
	 * 取出Shiro中的当前用户name.
	 * 
	 * @return
	 */
	public static String getName() {
		try {
			ShiroDbRealm.ShiroUser user = (ShiroDbRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal();
			return user.name;
		}catch (Exception e){
			e.printStackTrace();
		}
		return null;
	}

	public static Long getUserId() {
		ShiroDbRealm.ShiroUser user = (ShiroDbRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal();
		return user.id;
	}
	

}
